
package com.huaweicloud.saaslanding.install.properties;

import static com.huaweicloud.saaslanding.install.constant.ModelConstant.SUBNET_PREFIX;

import com.huaweicloud.saaslanding.basic.utils.CheckNullUtil;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

/**
 * 子网信息
 *
 * @since 2022-03-24
 */
@EqualsAndHashCode
@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
@Validated
@ConfigurationProperties(prefix = SUBNET_PREFIX)
public class SubnetInfo {

    /**
     * 是否启用单体应用部署
     */
    @Value("${saaslanding-install.mono-app.enabled:false}")
    private Boolean monoEnabled;

    /**
     * 是否启用License应用部署
     */
    @Value("${saaslanding-install.license-app.enabled:false}")
    private Boolean licenseEnabled;

    /**
     * 应用子网 ID
     */
    private String appSubnetId;

    /**
     * 应用子网名称
     */
    private String appSubnetName;

    /**
     * License服务器子网ID
     */
    private String licenseSubnetId;

    /**
     * License服务器子网名称
     */
    private String licenseSubnetName;

    public String getAppSubnetId() {
        if (monoEnabled && CheckNullUtil.isNotNull(appSubnetId)) {
            return appSubnetId;
        } else {
            throw new IllegalArgumentException("未启用单体应用部署或未配置应用子网ID(appSubnetId)");
        }
    }

    public String getAppSubnetName() {
        if (monoEnabled && CheckNullUtil.isNotNull(appSubnetName)) {
            return appSubnetName;
        } else {
            throw new IllegalArgumentException("未启用单体应用部署或未配置应用子网名称(appSubnetName)");
        }
    }

    public String getLicenseSubnetId() {
        if (licenseEnabled && CheckNullUtil.isNotNull(licenseSubnetId)) {
            return licenseSubnetId;
        } else {
            throw new IllegalArgumentException("未启用License应用部署或未配置License服务器子网ID(licenseSubnetId)");
        }
    }

    public String getLicenseSubnetName() {
        if (licenseEnabled && CheckNullUtil.isNotNull(licenseSubnetName)) {
            return licenseSubnetName;
        } else {
            throw new IllegalArgumentException("未启用License应用部署或未配置License服务器子网名称(licenseSubnetName)");
        }
    }

}
